home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Utilities / Text / OzTeX 1.9 / PS-files / DVItoPS.pro < prev    next >
Text File  |  1995-04-16  |  13KB  |  412 lines

  1. %!
  2. % This is the prolog used by OzTeX 1.9 to convert a DVI file into PostScript.
  3. % Uncomment the following line to prevent a timeout error when creating
  4. % missing PK fonts.
  5.  
  6. % statusdict begin /waittimeout 0 def end
  7.  
  8. % Set dev to "LW" if LaserWriter, "LINO" if Linotronic, or "?" if unknown.
  9.  
  10. /dev (?) def
  11. statusdict /product known {
  12.     statusdict /product get
  13.     (LaserWriter) anchorsearch { pop pop /dev (LW) def } { pop } ifelse
  14.     statusdict /product get
  15.     (Linotype) anchorsearch { pop pop /dev (LINO) def } { pop } ifelse
  16. } if
  17.  
  18. /@setup {                            % set up OzTeX's coordinate system
  19.  
  20. /res  exch def                        % desired resolution (defines dots per inch)
  21. /voff exch def                        % vertical offset (in dots)
  22. /hoff exch def                        % horizontal offset (in dots)
  23. /ht exch def                        % paper height (in dots)
  24. /wd exch def                        % paper width (in dots)
  25.  
  26. /land wd ht gt def                % print in landscape orientation?
  27. /oshift ht res sub neg def        % vertical shift (in dots) for portrait origin
  28.  
  29. dev (?) eq                                        % unknown device?
  30. { land
  31.     {                                                % landscape
  32.         90 rotate                                % rotate axes 90deg anticlockwise
  33.         72 res div dup neg scale            % units now device dots
  34.         res dup translate                        % move to TeX origin
  35.         voff neg hoff translate                % adjust TeX origin if necessary
  36.     }
  37.     {                                                % portrait
  38.         72 res div dup neg scale            % units now device dots
  39.         res oshift translate                    % move to TeX origin
  40.         hoff voff translate                    % adjust TeX origin if necessary
  41.     } ifelse
  42. } if
  43.  
  44. dev (LW) eq                                        % LaserWriter?
  45. {
  46.     % Display model and version in OzTeX window.
  47.     % (\rmodel = ) print statusdict /product get print
  48.     % (\rversion = ) print version print (\r) print flush
  49.  
  50.    land
  51.     {                                                % landscape
  52.         90 rotate                                % rotate axes 90deg anticlockwise
  53.         72 res div dup neg scale            % units now device dots
  54.         res dup translate                        % move to TeX origin
  55.         voff neg hoff translate                % adjust TeX origin if necessary
  56.         
  57.         % Model-specific adjustments to origin can be made here.
  58.         statusdict /product get (LaserWriter) eq
  59.         { -90 0 translate                                                % move left a bit
  60.         }
  61.         { statusdict /product get (LaserWriter Plus) eq
  62.         { -32 0 translate                                                % move left a bit
  63.         }
  64.         { statusdict /product get (LaserWriter II NTX) eq
  65.         { -20 0 translate                                                % move left a bit
  66.         }
  67.         { statusdict /product get (LaserWriter IIg) eq
  68.         { 0 0 translate
  69.         }
  70.         { % some other model
  71.           0 0 translate
  72.         }
  73.         ifelse } ifelse } ifelse } ifelse
  74.     }
  75.     {                                                % portrait
  76.         72 res div dup neg scale            % units now device dots
  77.         res oshift translate                    % move to TeX origin
  78.         hoff voff translate                    % adjust TeX origin if necessary
  79.         
  80.         % Model-specific adjustments to origin can be made here.
  81.         statusdict /product get (LaserWriter) eq
  82.         { 0 22 translate                                                % move down a bit
  83.         }
  84.         { statusdict /product get (LaserWriter Plus) eq
  85.         { 0 0 translate
  86.         }
  87.         { statusdict /product get (LaserWriter II NTX) eq
  88.         { 0 14 translate                                                % move down a bit
  89.         }
  90.         { statusdict /product get (LaserWriter IIg) eq
  91.         { 0 0 translate
  92.         }
  93.         { % some other model
  94.           0 0 translate
  95.         }
  96.         ifelse } ifelse } ifelse } ifelse
  97.     } ifelse
  98.     
  99.     % The matrix produced above can cause rule alignment problems,
  100.     % so round each matrix value to nearest integer.
  101.  
  102.     matrix currentmatrix
  103.     dup dup 0 get round cvi 0 exch put
  104.     dup dup 1 get round cvi 1 exch put
  105.     dup dup 2 get round cvi 2 exch put
  106.     dup dup 3 get round cvi 3 exch put
  107.     dup dup 4 get round cvi 4 exch put
  108.     dup dup 5 get round cvi 5 exch put
  109.     setmatrix
  110.     
  111.     % Display new matrix in OzTeX window.
  112.  
  113.     % matrix currentmatrix
  114.     % dup 0 get (            ) cvs print ( ) print
  115.     % dup 1 get (            ) cvs print ( ) print
  116.     % dup 2 get (            ) cvs print ( ) print
  117.     % dup 3 get (            ) cvs print ( ) print
  118.     % dup 4 get (            ) cvs print ( ) print
  119.     % dup 5 get (            ) cvs print (\r) print flush
  120.     % pop
  121. } if
  122.  
  123. dev (LINO) eq                                    % Linotronic?
  124. { land
  125.   {                                                % landscape
  126.      90 rotate                                    % rotate axes 90deg anticlockwise
  127.      72 res div dup neg scale                % units now device dots
  128.      res dup translate                        % move to TeX origin
  129.      voff neg hoff translate                % adjust TeX origin if necessary
  130.   }
  131.   {                                                % portrait
  132.      newpath clippath pathbbox                % push LLx LLy URx URy (URy = ht in pts)
  133.      /paperht exch 72 div def                % paper height in inches
  134.      pop pop pop                                % remove URx LLy LLx
  135.      72 res div dup neg scale                % units now device dots
  136.      res paperht res mul neg res add
  137.                                   translate        % move to TeX origin
  138.      hoff voff translate                        % adjust TeX origin if necessary
  139.   } ifelse
  140. } if
  141.  
  142. % Some fine-tuning of the code used to draw a rule may be necessary.
  143. % Use page 18 in nasty.dvi to check the results.
  144.  
  145. dev (LW) eq                                    % LaserWriter?
  146. { version cvr 38.0 le                    % early model?
  147.   { land
  148.     {                                            % landscape
  149.           /r                                    % set a wd by ht rule at h,v
  150.           { newpath
  151.              moveto                            % move to h,v
  152.              /ht exch 1 sub def            % reduce height by 1
  153.              /wd exch 1 sub def            % ditto for width
  154.              wd 0 rlineto
  155.              0 ht neg rlineto
  156.              wd neg 0 rlineto
  157.              fill
  158.           } bind def
  159.       }
  160.       {                                        % portrait
  161.           /r                                    % set a wd by ht rule at h,v
  162.           { newpath
  163.              1 add moveto                    % move to h,v+1
  164.              /ht exch 1 sub def            % reduce height by 1
  165.              /wd exch 1 sub def            % ditto for width
  166.              wd 0 rlineto
  167.              0 ht neg rlineto
  168.              wd neg 0 rlineto
  169.              fill
  170.           } bind def
  171.       } ifelse
  172.   } if
  173.   version cvr 2000.0 gt                    % IIg or newer model?
  174.   {
  175.       /r                                        % set a wd by ht rule at h,v
  176.       { newpath
  177.          1 add moveto                        % move to h,v+1
  178.          /ht exch def                        % set height
  179.          /wd exch def                        % set width
  180.          wd 0 rlineto
  181.          0 ht neg rlineto
  182.          wd neg 0 rlineto
  183.          fill
  184.       } bind def
  185.   } if
  186. } if
  187.  
  188. /mtrx 6 array def
  189. mtrx currentmatrix pop                    % save our new transformation matrix
  190.  
  191. } def % @setup
  192.  
  193. % @saveVM and @restoreVM are only used if we are conserving VM
  194. % by downloading font bitmaps more often.
  195.  
  196. /@saveVM {/prefontVM save def} def
  197. /@restoreVM {prefontVM restore} def
  198.  
  199. /newPKfont                                    % create new PK font
  200. { /maxchcode exch def
  201.   /fontid exch def
  202.   fontid 7 dict def
  203.   fontid load begin
  204.       /FontType 3 def
  205.       /FontMatrix [1 0 0 -1 0 0] def
  206.       /FontBBox [0 0 1 1] def
  207.       /BitMaps maxchcode 1 add array def
  208.       /BuildChar {CharBuilder} def
  209.       /Encoding 256 array def
  210.       0 1 255 {Encoding exch /.notdef put} for
  211.       end
  212.   fontid fontid load definefont pop
  213. } def
  214.  
  215. % The char data, a bitmap descriptor, is an array with 6 elements;
  216. % element 0 is either a hex string or an array of hex strings (the latter
  217. % is required for large PK chars with more than 65535 hex digits).
  218.  
  219. /ch-image    {ch-data 0 get dup type /stringtype ne {N get /N N 1 add def} if
  220.                 } def                            % hex string
  221. /ch-width    {ch-data 1 get} def        % the number of pixels across
  222. /ch-height    {ch-data 2 get} def        % the number of pixels tall
  223. /ch-xoff        {ch-data 3 get} def        % number of pixels to left of origin
  224. /ch-yoff        {ch-data 4 get} def        % number of pixels below origin
  225. /ch-advw        {ch-data 5 get} def        % advance width
  226.  
  227. % The following character builder looks up the char data in the BitMaps array
  228. % and paints the character.
  229.  
  230. /CharBuilder                                % image one char
  231. { /ch-code exch def                        % save the char code
  232.   /font-dict exch def                    % and the font dict
  233.   /ch-data font-dict /BitMaps get
  234.   ch-code get def
  235.   /N 0 def
  236.       ch-advw 0
  237.       ch-xoff neg ch-height ch-yoff sub 1 sub neg    % -xo , -(ht-yo-1)
  238.       ch-width ch-xoff sub 1 sub ch-yoff                % (wd-xo-1) , yo
  239.   setcachedevice
  240.       ch-width ch-height true
  241.       [1 0 0 -1 ch-xoff ch-yoff]        % bitmap sent top to bottom
  242.       {ch-image}
  243.   imagemask
  244. } def
  245.  
  246. /sf {setfont} def                            % set current font
  247.  
  248. /dc                                            % define new character
  249. { /ch-code exch def
  250.   /ch-data exch def
  251.   currentfont /BitMaps get ch-code ch-data put
  252.   currentfont /Encoding get ch-code
  253.   dup (   ) cvs cvn put                    % generate unique name
  254. } bind def
  255.  
  256. /@bop0 {pop} def                            % begin DVI page n
  257.  
  258. /@bop1                                        % begin setting DVI page n
  259. { pop                                            % throw away page number
  260.   initgraphics                                % start with a clean slate
  261.   mtrx setmatrix                            % switch to our TeX coordinate system
  262.   /prepageVM save def                    % save state of VM at start of page
  263. } def
  264.  
  265. /@eop                                            % end DVI page n
  266. { pop                                            % throw away page number
  267.   prepageVM restore                        % restore VM to state at start of page
  268.   showpage
  269. } def
  270.  
  271. /@end { } def                                % end of file
  272.  
  273. % h and s are used to typeset downloaded bitmap fonts.
  274.  
  275. /h {exch 0 rmoveto show} bind def    % move right by dh and show (...)
  276.  
  277. /s {3 1 roll moveto show} bind def    % move to h,v and show (...)
  278.  
  279. % H and S are used to typeset PostScript fonts.
  280. % We can't use relative horizontal positioning because the advance widths in
  281. % a PostScript font are not integers and rounding errors would accumulate.
  282.  
  283. /H {exch v moveto show} bind def        % move to h,v and show (...)
  284.  
  285. /S                                                % ditto, and save v position
  286. { 3 1 roll
  287.   1 add                                        % v+1 to match baseline of bitmap fonts
  288.   dup /v exch def
  289.   moveto show
  290. } bind def
  291.  
  292. % r is used to typeset a rule.
  293.  
  294. /r                                                % set a wd by ht rule at h,v
  295. { newpath
  296.   moveto                                        % move to h,v
  297.   /ht exch 1 sub def                        % reduce height by 1
  298.   /wd exch 1 sub def                        % ditto for width
  299.   wd 0 rlineto
  300.   0 ht neg rlineto
  301.   wd neg 0 rlineto
  302.   fill
  303. } bind def
  304.  
  305. % Following 2 procedures are invoked as the result of \special{file}.
  306.  
  307. /@bsp
  308. { /vmag exch def                            % vertical scaling
  309.   /hmag exch def                            % horizontal scaling
  310.   moveto                                        % move to h,v
  311.   /prespecialVM save def                % save showpage, TeX procedures etc.
  312.   userdict begin                            % push userdict on dict stack
  313.   /showpage { } def                        % user does not have to remove showpage
  314.   currentpoint transform
  315.   initgraphics itransform translate % move 0,0 to h,v
  316.   hmag vmag scale
  317.   land { 90 rotate } if                    % rotate axes if landscape
  318. } bind def
  319.  
  320. /@esp
  321. { end                                            % pop userdict
  322.   prespecialVM restore                    % restore saved showpage value etc
  323. } bind def
  324.  
  325. % Following 2 procedures are invoked as the result of \special{epsf=file}.
  326.  
  327. /@bepsf
  328. { /lly exch def                            % LLy for BoundingBox
  329.   /llx exch def                            % LLx for BoundingBox
  330.   /vmag exch def                            % vertical scaling
  331.   /hmag exch def                            % horizontal scaling
  332.   /vpos exch def                            % v pos of \special box
  333.   /hpos exch def                            % h pos of \special box
  334.   /prespecialVM save def                % save showpage, TeX procedures etc
  335.   userdict begin                            % push userdict on dict stack
  336.   /showpage { } def                        % user does not have to remove showpage
  337.   hpos vpos translate                    % move 0,0 to h,v
  338.   hmag vmag scale                            % scale BoundingBox
  339.   llx neg lly neg translate            % move LLx,LLy to h,v
  340. } bind def
  341.  
  342. /@eepsf
  343. { end                                            % pop userdict
  344.   prespecialVM restore                    % restore saved showpage value etc
  345. } bind def
  346.  
  347. % Here is the code to handle bitmaps generated by PICT/PNTG \specials.
  348.  
  349. /@bitmap
  350. { /vmag exch def                            % vertical scaling
  351.   /hmag exch def                            % horizontal scaling
  352.   /vres exch def                            % vertical resolution of bitmap
  353.   /hres exch def                            % horizontal resolution of bitmap
  354.   /ht exch def                                % height
  355.   /wd exch def                                % width
  356.   /hexstring ht string def
  357.   gsave
  358.      1 add translate                        % set origin to h,v+1
  359.      res hres div wd mul hmag mul
  360.      res vres div ht mul vmag mul neg scale
  361.      wd ht true
  362.      [ wd 0 0 ht neg 0 ht ]
  363.      { currentfile hexstring readhexstring pop }
  364.      imagemask
  365.   grestore
  366. } def
  367.  
  368. % Here are the definitions needed to handle PostScript fonts.
  369.  
  370. /namestr 60 string def                    % for names
  371. /numstr 12 string def                    % for numbers
  372.  
  373. /newPSfont                                    % create new PS font
  374. { /fontname exch def                        % printer font name
  375.   /mag exch def                            % DVI mag
  376.   /scaledpts exch def                    % font size in scaled pts
  377.  
  378.   % Use scaledpts and mag to calculate font size in device dots.
  379.   scaledpts 16#10000 div                % scaled pts to pts
  380.   res mul 72.27 div                        % pts to device dots
  381.   mag 1000 div mul                        % scale by mag/1000
  382.   /dotsize exch def
  383.   /done false def
  384.   
  385.   % If fontname starts with "Slanted-" then construct slanted font.
  386.   fontname namestr cvs (Slanted-) anchorsearch
  387.   { pop cvn findfont [1 0 .167 -1 0 0] makefont dotsize scalefont
  388.     /done true def
  389.   }{ pop } ifelse
  390.  
  391.   % Other nice tricks can be included here if you build the required
  392.   % fonts and add appropriate printer font names to your config file.
  393.   % fontname namestr cvs (Extended-) anchorsearch
  394.   % { pop cvn findfont [1.2 0 0 -1 0 0] makefont dotsize scalefont
  395.   %   /done true def
  396.   % }{ pop } ifelse
  397.   
  398.   done not
  399.   { fontname findfont [1 0 0 -1 0 0] makefont dotsize scalefont
  400.   } if
  401.  
  402.   % Modified font dictionary is on stack, so remember it for later setfont
  403.   % via a unique name that is the concatenation of fontname and scaledpts.
  404.   fontname length scaledpts numstr cvs length add
  405.   /newname exch string def
  406.   newname 0 fontname namestr cvs putinterval
  407.   newname fontname length scaledpts numstr cvs putinterval
  408.   newname cvn exch def
  409. } bind def
  410.  
  411. % --- end of OzTeX's prolog ---
  412.